package com.scqkxx.gamebox.activity.myself.adapter;

import android.content.ContentValues;
import android.view.View;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.activities.utils.ActivityUtil;
import com.scqkxx.gamebox.activity.myself.MyselfEditNicknameActivity;
import com.scqkxx.gamebox.activity.myself.MyselfEditSignatureActivity;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 物品是配置器
 */
public class GoodsAdapter extends BaseQuickAdapter<AVObject ,BaseViewHolder> {
    private int spaceState = 0;

    public GoodsAdapter(int layoutResId, List<AVObject> data , int spaceState) {
        super(layoutResId, data);
        this.spaceState = spaceState;
    }

    @Override
    protected void convert(BaseViewHolder helper, AVObject item) {
        ((TextView)helper.getView(R.id.good_name)).setText(item.getString("name"));
        ((TextView)helper.getView(R.id.createTime)).setText(new SimpleDateFormat("yyyy年MM月dd日").format(item.getCreatedAt()));
        if (spaceState == 2){
            helper.getView(R.id.lins).setVisibility(View.GONE);
            helper.getView(R.id.content2).setVisibility(View.GONE);
        }else{
            helper.getView(R.id.lins).setVisibility(View.VISIBLE);
            helper.getView(R.id.content2).setVisibility(View.VISIBLE);
            ((TextView)helper.getView(R.id.good_index)).setText(item.get("goodsNum")+"");
        }
        helper.getView(R.id.spacer).setOnClickListener(v -> {
            ContentValues contentValues = new ContentValues();
            contentValues.put("objectId" ,item.getObjectId());
            contentValues.put("belongGroupId" , (Integer) item.get("belongGroupId") );
            contentValues.put("spaceId" , (Integer) item.get("spaceId") );
            if (spaceState == 2){
                ActivityUtil.switchTo(mContext ,MyselfEditSignatureActivity.class ,contentValues);
            } else {
                contentValues.put("spaceState" ,2 );
                contentValues.put("belongGroupId" ,(Integer) item.get("belongGroupId") );
                contentValues.put("objectId" ,item.getObjectId());
                contentValues.put("spaceId" ,Integer.valueOf(item.getObjectId()));
                ActivityUtil.switchTo(mContext ,MyselfEditNicknameActivity.class ,contentValues);
            }
        });
    }
}
